<template>
  <div class="home">
    <van-search shape="round" v-model="value" placeholder="请输入搜索关键词" disabled @click="openPopup" />
    
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="#1989fa">
      <van-swipe-item v-for="item in banner" :key="item.id">
        <!-- <img :src="item.image_url" alt /> -->
        <img v-lazy="item.image_url" width="100%" style="display:block" />
      </van-swipe-item>
    </van-swipe>

    <Channel :channel="channel" />
    <Brand :brandList="brandList" />
    <New :newGoodsList="newGoodsList" />
    <Hot :hotGoodsList="hotGoodsList" />
    <Topic :topicList="topicList" />
    <Category :categoryList="categoryList" />

    <transition name="slide">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </transition>
    <transition name="fade">
      <div class="popuoBg" v-if="$store.state.showPopup"></div>
    </transition>
  </div>
</template>

<script>
// @ is an alias to /src
import { GetIndex } from "@/request/api";
import Channel from "@/components/home/Channel";
import Brand from "../components/home/Brand";
import New from "../components/home/New";
import Hot from "../components/home/Hot";
import Topic from "../components/home/Topic";
import Category from "../components/home/Category";

export default {
  name: "Home",
  data() {
    return {
      value: "",
      banner: [],
      channel: [],
      newGoodsList: [],
      hotGoodsList: [],
      brandList: [],
      topicList: [],
      categoryList: [],
    };
  },
  components: {
    Channel,
    Brand,
    New,
    Hot,
    Topic,
    Category,
  },
  methods: {
    openPopup() {
      this.$router.push("/home/popup");
      this.$store.commit("changeShowPopup", true);
    },
  },
  created() {
    GetIndex().then((res) => {
      if (res.errno == 0) {
        // console.log(res);
        this.banner = res.data.banner;
        this.channel = res.data.channel;
        this.newGoodsList = res.data.newGoodsList;
        this.hotGoodsList = res.data.hotGoodsList;
        this.brandList = res.data.brandList;
        this.topicList = res.data.topicList;
        this.categoryList = res.data.categoryList;
      }
    });
  },
};
</script>

<style lang="less">
.home {
  padding-bottom: 50px;
}
.popuoBg {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  overflow: scroll;
  z-index: 1;
}
.title {
  height: 50px;
  line-height: 50px;
  text-align: center;
}
.slide-enter,
.slide-leave-to {
  right: -100%;
}
.slide-enter-active,
.slide-leave-active {
  transition: right 0.5s;
}
.slide-enter-to,
.slide-leave {
  right: 0;
}

.fade-enter,
.fade-leave-to {
  opacity: 0.5;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter-to,
.fade-leave {
  opacity: 1;
}

/deep/.van-swipe__indicator {
  opacity: 1;
  background-color: #aaaaaa;
}
</style>